import { getSerialNumListApi } from '@/views/master/serialnumber/api/serialnumber.api';
import { getCurrencyRateListApi } from '@/views/master/currencyrate/api/currencyrate.api';
import { getDepartmentsListApi } from '@/views/master/departments/api/departments.api';
import { getCurrencyListApi } from '@/views/master/currency/api/currency.api';

const state = {
  serialNumberList: [],
  currencyRateList: [],
  departmentsList: [],
  currencyList: []
};

const mutations = {
  SET_SERIALNUM_LIST: (state, data) => {
    state.serialNumberList = data;
  },
  SET_CURRENCYRATE_LIST: (state, data) => {
    state.currencyRateList = data;
  },
  SET_DEPARTMENTS_LIST: (state, data) => {
    state.departmentsList = data;
  },
  SET_CURRENCY_LIST: (state, data) => {
    state.currencyList = data;
  }
};

const actions = {
  getSerialNumberList({ commit }, queryParams) {
    return new Promise((resolve, reject) => {
      getSerialNumListApi(queryParams).then(response => {
        const { data } = response;
        const { results } = data
        commit('SET_SERIALNUM_LIST', results);
        resolve(response)
      }).catch(error => {
        reject(error);
      });
    });
  },
  getCurrencyRateList({ commit }, queryParams) {
    return new Promise((resolve, reject) => {
      getCurrencyRateListApi(queryParams).then(response => {
        const { data } = response;
        const { results } = data
        commit('SET_CURRENCYRATE_LIST', results);
        resolve(response)
      }).catch(error => {
        reject(error);
      });
    });
  },
  getDepartmentsList({ commit }, queryParams) {
    return new Promise((resolve, reject) => {
      getDepartmentsListApi(queryParams).then(response => {
        const { data } = response;
        const { results } = data
        commit('SET_DEPARTMENTS_LIST', results);
        resolve(response)
      }).catch(error => {
        reject(error);
      });
    });
  },
  getCurrencyList({ commit }, queryParams) {
    return new Promise((resolve, reject) => {
      getCurrencyListApi(queryParams).then(response => {
        const { data } = response;
        const { results } = data
        commit('SET_CURRENCY_LIST', results);
        resolve(response)
      }).catch(error => {
        reject(error);
      });
    });
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
